﻿@model IEnumerable<Swift.Core.Member>

@{
    ViewBag.Title = "成员";
}

@section scripts{
<script type="text/javascript">

    function refreshpage()
    {
       window.location.reload();
    }
    setTimeout('refreshpage()',5000);

    $('#restartResultModal').on('hide.bs.modal', function () {
        window.location.reload();
    });

    $("#btnRestartManagerElection").on("click", function() {
        $.ajax({
            url: "@Url.Action("RestartManagerElection","Home")",
            type:"GET",
            dataType:"json",
            data:{"cluster":"@ViewBag.ClusterName"},
            success: function(data,textStatus){
                if(data.errCode==0){
                        $("#restartResultModal .modal-title").text("提交成功");
                        $("#restartResultModal .modal-body").text("页面将很快刷新，需要注意新的Manager有可能还是原节点。");
                        $('#restartResultModal').modal({ keyboard: false });
                }else{
                        $("#restartResultModal .modal-title").text("提交失败");
                        $("#restartResultModal .modal-body").text(data.errMessage);
                        $('#restartResultModal').modal({ keyboard: false });
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert("提交失败");
            }
        });
    });
</script>
}

<h2>集群 @ViewBag.ClusterName 成员</h2>

<p>
    <a class="btn btn-info" href="@Url.Action("Index","Home")">返回</a>
    <a class="btn btn-info" href="javascript:location.reload()">刷新</a>
</p>
<p class="text-right">
    <button id="btnRestartManagerElection" type="button" class="btn btn-primary">重启Manager选举</button>
</p>
<table class="table table-striped table-hover">
    <tr>
        <th>
            Id
        </th>
        <th>
            状态
        </th>
        <th>
            最近上线时间
        </th>
        <th>
            最近离线时间
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td class="col-md-3">
                @Html.DisplayFor(modelItem => item.Id)

                @{
                    if (ViewBag.Manager != null && ViewBag.Manager.Id == item.Id)
                    {
                        <span> (Manager)</span>
                    }
                }
            </td>
            <td class="col-md-3">
                @(item.Status == 0 ? "离线" : "在线")
            </td>
            <td class="col-md-3">
                @(item.OnlineTime.HasValue ? item.OnlineTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty)
            </td>
            <td class="col-md-3">
                @(item.OfflineTime.HasValue ? item.OfflineTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty)
            </td>
        </tr>
    }
</table>

<div class="modal fade" id="restartResultModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>